<div cache='user' class='bc-info' data-port='http://api.hongyanche.com/user/info'>
	<tel info=none style="padding:50px;color:#666">还未绑定手机，无法找回密码</tel>
	<tel info=d>
		<div class='weui-cells' style="color:#666">
			<div class='weui-cell'>
				<div class='weui-cell__hd' style='width:70px;'>
					手机号码
				</div>
				<div class='weui-cell__bd'>
					<tel info=1></tel>
				</div>
				<div class='weui-cell__ft'>
					<a id="password-reset-send" style="margin-top: 0px;" class='weui-btn weui-btn_default weui-btn_mini'>发送</a>
				</div>
			</div>
			<div class='weui-cell' id="password-reset-vcode-cell" style='display: none;'>
				<div class='weui-cell__hd' style='width:70px;'>图形码</div>
				<div class='weui-cell__bd'>
					<form onsubmit="$('#password-reset-send').trigger('click')">
						<input type='email' id='password-reset-vcode' class='login-vcode-input weui-input' name='vcode' placeholder="输入图形码" />
					</form>
				</div>
				<div class='weui-cell__ft'><img class='vcode' onclick='$(".vcode").prop("src","/vcode")'/></div>
			</div>
			<div class='weui-cell'>
				<div class='weui-cell__hd' style='width:70px;'>
					验证码
				</div>
				<div class='weui-cell__bd'>
					<form onsubmit="$('#password-reset-submit').trigger('click')"><input type='tel' id="password-reset-code" class='weui-input' placeholder="输入验证码" /></form>
				</div>
			</div>
			<div class='weui-cell bc-input-focus1'>
				<div class='weui-cell__hd' style='width:70px;'>新密码</div>
				<div class='weui-cell__bd'><form onsubmit="$('#password-reset-submit').trigger('click')"><input id="password" type='password' class='weui-input' name='password' placeholder="请输入密码" /></form></div>
			</div>
			<div class='weui-cell bc-input-focus1'>
				<div class='weui-cell__hd' style='width:70px;'>确认密码</div>
				<div class='weui-cell__bd'><form onsubmit="$('#password-reset-submit').trigger('click')"><input id="passwordx" type='password' class='weui-input' name='passwordx' placeholder="确认密码" /></form></div>
			</div>
			<div class='weui-btn-area'>
				<a id="password-reset-submit" class='weui-btn weui-btn_primary weui-btn_disabled'>重设密码</a>
			</div>
	</tel>
</div>
<script>
    login_code = {
        init:function(){
            var s = $("#password-reset-send");
            var v = $("#password-reset-vcode");
            var cell = $("#password-reset-vcode-cell")
            var c = $("#password-reset-code");
            var b = $("#password-reset-submit");
            var p = $('#password');
            var px = $('#passwordx');
            var password_reg = /((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}$/;
            POST.init(s,{
                url:"/user/password_reset",
                text:"发送",
                success:function(e,res){
                    cell.hide();
                    c.val('');
                    c.focus();
                    b.removeClass('weui-btn_disabled');
                    var remain = res.data
                    if(remain) remain = remain.remain;
                    if(remain) TIMER.start(s,remain);
                },
                input:function(){
                    return {vcode:v.val()}
                },
                error:function(e,res){
                    switch(res.errormsg){
                        case "vcode error":
                            cell.fadeIn();
                            $(".vcode").addClass("active")
                            $(".vcode").attr('src','/vcode')
                            v.val('')
                            v.focus();
                            break;
                        default:
                            cell.hide();
                            break;
                    }
                    var remain = res.data
                    if(remain) remain = remain.remain;
                    if(remain) TIMER.start(s,remain);
                },
                msg:{
                    "vcode error":"图形码不正确",
                    "token cooling":"请稍后再发送",
                    "token too much":"请稍后再发送",
                    "sms cooling":"请稍后再发送",
                }
            })
            POST.init(b,{
                url:"/user/password_reset",
                input:function(){
                    var password = p.val();
                    return {code:c.val(),vcode:v.val(),password:password}
                },
                stop:function(){
                    var password = p.val();
                    var passwordx = px.val();
                    if(!password_reg.test(password)){
                        var errormsg = '请输入正确的密码(大小写字母+数字8-16位的组合)';
                        err.html(errormsg);
                        alert(errormsg,' ',1);
                        p.focus();
                        return true;
                    }
                    if(!password){
                        alert('密码不能为空')
                        p.focus();
                        return true;
                    }
                    if(!passwordx){
                        alert('请确认密码')
                        px.focus();
                        return true;
                    }
                    if(password !== passwordx){
                        alert('两次密码不一致')
                        p.focus();
                        return true;
                    }
                },
                text:"重置",
                error:function(e,res){
                    switch(res.errormsg){
                        case "vcode error":
                            cell.fadeIn();
                            $(".vcode").addClass("active")
                            $(".vcode").attr('src','/vcode')
                            v.val('')
                            v.focus();
                            break;
                        default:
                            cell.hide();
                            break;
                    }
                },
                success:function(){
                    $(document).trigger("password-reset-success");
                },
                msg:{
                    "vcode error":"图形码不正确",
                    "code error":"验证码不正确",
                    "check too much":"错误太多，请重新发送",
                }
            })
        }
    }
    login_code.init()

</script>